/** @namespace app.spider.Anchor */
module.exports = app => {
  const {STRING, INTEGER, TINYINT} = app.Sequelize;
  const Anchor = app.spider.define('anchor', {
    name: {
      type: STRING,
      allowNull: false,
    },
    room: {type: STRING, allowNull: false},//房间号
    avatar: {type: STRING},//主播头像
    gender: {type: TINYINT(1).UNSIGNED, defaultValue: 0},//性别 0未知 1男 2女
    num_follower: {type: INTEGER.UNSIGNED, defaultValue: 0},//关注 人数
    num_gift: {type: INTEGER.UNSIGNED, defaultValue: 0},//礼物 价值
    num_live: {type: INTEGER.UNSIGNED, defaultValue: 0},//累计直播 单位 分钟
  }, {
    timestamps: false,
    tableName: 'spider_anchor',
    indexes: [
      {
        unique: true,
        name: 'platform_room_unique',
        fields: ['room', 'platform_id'],
      },
    ],
  });

  Anchor.associate = () => {

    //【主播】与【平台】绑定
    app.spider.Anchor.belongsTo(app.spider.Platform,
      {foreignKey: {name: 'platform_id', allowNull: false}});
    app.spider.Platform.hasMany(app.spider.Anchor,
      {foreignKey: {name: 'platform_id', allowNull: false}});

  };

  return Anchor;
};